import jieba.analyse
from sqlalchemy import create_engine
import psycopg2
import pandas as pd
# 把已有的库进行分词,统计词频
# 连接数据库
conn = psycopg2.connect(database='ltzd', user='ai',
                        password='ai001', host='127.0.0.1', port='5432')

 

# 编写Sql，只取前两行数据
sql = 'select a.keywords  from ai_ltzd_all a where length(a.keywords)!=0 limit 1000' 

# 获得数据
df = pd.read_sql_query(sql, conn)

print(df)
#df.reset_index(level=0, inplace=True)

# print(pd_data)

# 关闭指针和数据库
 
conn.close()


#词频统计
 
import collections
strss=''
for strs in df['keywords']:
    strss=strs+strss

sss=collections.Counter( strss.split() )
print(sss)


 